var t = getApp();

Page({
    data: {
        checked: !0,
        sexShow: !1,
        showAdd: !1,
        member_type: 1,
        identity_number: "",
        identity_front_image: "",
        identity_back_image: "",
        name: "",
        sex: "1",
        live_province_id: "",
        live_city_id: "",
        live_district_id: "",
        live_street_id: "",
        live_address: "",
        source_province_id: "",
        source_city_id: "",
        source_district_id: "",
        source_street_id: "",
        source_address: "",
        agreement_pics: "",
        another_pics: "",
        business_pics: "",
        showAddTwo: !1,
        debtor_uid: "",
        addressOne: "",
        addressTwo: "",
        streetShowtwo: !1,
        streettwo: "",
        streetShow: !1,
        street: "",
        districtVal: [],
        identity_front_image_show: "",
        identity_back_image_show: "",
        settingInfo: [],
        descShow: !1,
        Vip_uid: [],
        showUserC: []
    },
    onLoad: function(t) {
        t.type && this.setData({
            member_type: t.type
        }), wx.setNavigationBarTitle({
            title: 1 == this.data.member_type ? "债权人申请" : 2 == this.data.member_type ? "债务人申请" : "VIP申请"
        }), 3 == this.data.member_type && this.getVipUser();
    },
    tapDescOpen: function() {
        this.setData({
            descShow: !0
        });
    },
    sdescShowClose: function() {
        this.setData({
            descShow: !1
        });
    },
    selectSex: function(t) {
        console.log(t, "aaaaaaa");
        var e = t.currentTarget.dataset.ind;
        this.setData({
            sex: e
        });
    },
    delIntu_1: function() {
        this.setData({
            identity_front_image_show: "",
            identity_front_image: ""
        }), this.selectComponent("#uploaderZ").setData({
            fileList1: [],
            fileImg: []
        });
    },
    delIntu_2: function() {
        this.setData({
            identity_back_image_show: "",
            identity_back_image: ""
        }), this.selectComponent("#uploaderF").setData({
            fileList1: [],
            fileImg: []
        });
    },
    updateImages: function(t) {
        "agreement" == t.currentTarget.dataset.key ? this.setData({
            agreement_pics: t.detail
        }) : "getIMgbusiness" == t.currentTarget.dataset.key ? this.setData({
            business_pics: t.detail
        }) : "getIMganother" == t.currentTarget.dataset.key && this.setData({
            another_pics: t.detail
        });
    },
    openSex: function() {
        this.setData({
            sexShow: !0
        });
    },
    sexShowClose: function() {
        this.setData({
            sexShow: !1
        });
    },
    onChange: function(t) {
        this.setData({
            checked: t.detail
        });
    },
    getIMg: function(t) {
        this.setData({
            identity_front_image: t.detail[0]
        });
    },
    getIMgF: function(t) {
        console.log(t, "identity_back_image"), this.setData({
            identity_back_image: t.detail[0]
        });
    },
    getIDcardZ: function(t) {
        this.setData({
            identity_front_image_show: t.detail[0]
        });
    },
    getIDcardF: function(t) {
        console.log(t, "getIDcardF"), this.setData({
            identity_back_image_show: t.detail[0]
        });
    },
    tapShowAdd: function(t) {
        "two" == t.currentTarget.dataset.key ? this.setData({
            showAddTwo: !0
        }) : this.setData({
            showAdd: !0
        });
    },
    resultAdd: function(t) {
        var e = t.detail;
        "two" == t.currentTarget.dataset.key ? this.setData({
            addressTwo: "".concat(e[0].name).concat(e[1].name).concat(e[2].name),
            source_province_id: e[0].id,
            source_city_id: e[1].id,
            source_district_id: e[2].id
        }) : this.setData({
            addressOne: "".concat(e[0].name).concat(e[1].name).concat(e[2].name),
            live_province_id: e[0].id,
            live_city_id: e[1].id,
            live_district_id: e[2].id
        });
    },
    tapStreetShow: function(e) {
        if ("two" == e.currentTarget.dataset.key) {
            if (!this.data.source_district_id) return t.tips("请先选择户籍所在区域");
            this._getStreet(this.data.source_district_id, "two");
        } else {
            if (!this.data.live_district_id) return t.tips("请先选择所在区域");
            this._getStreet(this.data.live_district_id, "one");
        }
    },
    _getStreet: function(e, i) {
        var s = this, a = this, d = t.getNetAddresss("member.memberAddress.street");
        d += "&district_id=" + e, t._getNetWork({
            url: d,
            success: function(e) {
                var d = e.data;
                1 != d.result || t._isTextEmpty(d.data) || !t._isTextEmpty(d.data) && d.data.length > 0 && ("one" == i ? s.setData({
                    streetShow: !0
                }) : s.setData({
                    streetShowtwo: !0
                }), a.setData({
                    districtVal: d.data
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    streetConfirm: function(t) {
        var e = t.target.dataset.strname;
        console.log(t), "one" == t.currentTarget.dataset.key ? this.setData({
            street: e,
            streetShow: !1,
            live_street_id: t.currentTarget.dataset.id
        }) : this.setData({
            streettwo: e,
            streetShowtwo: !1,
            source_street_id: t.currentTarget.dataset.id
        });
    },
    streetClose: function() {
        this.setData({
            streetShowtwo: !1,
            streetShow: !1
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    checkPost: function() {
        if (1 == this.data.member_type || 2 == this.data.member_type) {
            if (t._isTextEmpty(this.data.name)) return t.tips("请输入姓名"), !1;
            if (t._isTextEmpty(this.data.sex)) return t.tips("请选择性别"), !1;
            if (t._isTextEmpty(this.data.live_province_id) || t._isTextEmpty(this.data.live_city_id) || t._isTextEmpty(this.data.live_district_id)) return t.tips("请选择常住区域"), 
            !1;
            if (t._isTextEmpty(this.data.source_province_id) || t._isTextEmpty(this.data.source_city_id) || t._isTextEmpty(this.data.source_district_id)) return t.tips("请选择户籍区域"), 
            !1;
            if (t._isTextEmpty(this.data.agreement_pics)) return t.tips("请上传和解协议"), !1;
            if (t._isTextEmpty(this.data.another_pics)) return t.tips("请上传补充资料"), !1;
            if (this.data.settingInfo.is_street) {
                if (t._isTextEmpty(this.data.live_street_id)) return t.tips("请选择常住街道"), !1;
                if (t._isTextEmpty(this.data.source_street_id)) return t.tips("请选择户籍街道"), !1;
            }
        }
        return 2 == this.data.member_type && t._isTextEmpty(this.data.business_pics) ? (t.tips("请上传营业执照"), 
        !1) : 1 == this.data.member_type && t._isTextEmpty(this.data.debtor_uid) ? (t.tips("请输入债务人会员ID"), 
        !1) : t._isTextEmpty(this.data.identity_number) ? (t.tips("请输入身份证号码"), !1) : t._isTextEmpty(this.data.identity_front_image) || t._isTextEmpty(this.data.identity_back_image) ? (t.tips("请上传身份证图片"), 
        !1) : !(!t._isTextEmpty(this.data.settingInfo.apply_desc) && !this.data.checked) || (t.tips("请阅读勾选申请协议"), 
        !1);
    },
    submit: function() {
        var e = this;
        if (this.checkPost()) {
            var i = {
                member_type: this.data.member_type,
                identity_number: this.data.identity_number,
                identity_front_image: this.data.identity_front_image,
                identity_back_image: this.data.identity_back_image
            };
            2 != this.data.member_type && 1 != this.data.member_type || (i.name = this.data.name, 
            i.sex = this.data.sex, i.live_province_id = this.data.live_province_id, i.live_city_id = this.data.live_city_id, 
            i.live_city_id = this.data.live_city_id, i.live_district_id = this.data.live_district_id, 
            i.live_street_id = this.data.live_street_id, i.live_address = this.data.live_address, 
            i.source_province_id = this.data.source_province_id, i.source_city_id = this.data.source_city_id, 
            i.source_district_id = this.data.source_district_id, i.source_street_id = this.data.source_street_id, 
            i.source_address = this.data.source_address, i.agreement_pics = JSON.stringify(this.data.agreement_pics), 
            i.another_pics = JSON.stringify(this.data.another_pics)), 2 == this.data.member_type && (i.business_pics = JSON.stringify(this.data.business_pics)), 
            1 == this.data.member_type && (i.debtor_uid = this.data.debtor_uid), console.log("json ", i);
            var s = t.getNetAddresss("plugin.debt-shop.frontend.apply.apply");
            t._getNetWork({
                url: s,
                data: i,
                success: function(t) {
                    var i = t.data;
                    1 == i.result ? 3 == e.data.member_type ? wx.showModal({
                        title: "",
                        content: "您已提交申请VIP，等待商家审核",
                        confirmText: "知道了",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm && wx.navigateBack({
                                delta: 1
                            });
                        }
                    }) : wx.showToast({
                        title: "申请成功",
                        icon: "none",
                        duration: 1e3,
                        success: function(t) {
                            wx.navigateBack({
                                delta: 1
                            });
                        }
                    }) : wx.showToast({
                        icon: "none",
                        title: i.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    searchInp: function() {
        var e = this, i = t.getNetAddresss("member.member.memberInfo");
        t._getNetWork({
            url: i,
            data: {
                uid: this.data.debtor_uid
            },
            success: function(t) {
                var i = t.data;
                1 == i.result ? (console.log(i, "aaaaasc::::"), e.setData({
                    showUserC: i.data
                })) : wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getVipUser: function() {
        var e = this, i = t.getNetAddresss("plugin.debt-shop.frontend.debt-member.memberParentInfo");
        t._getNetWork({
            url: i,
            showToastIn: !0,
            success: function(t) {
                var i = t.data;
                1 == i.result ? (console.log(i, "aaaaasc::::"), e.setData({
                    Vip_uid: i.data
                })) : wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500,
                    success: function(t) {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3);
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getData: function() {
        var e = this, i = t.getNetAddresss("plugin.debt-shop.frontend.debt-member.applyData");
        t._getNetWork({
            url: i,
            data: {
                member_type: this.data.member_type
            },
            success: function(t) {
                var i = t.data;
                if (1 == i.result) {
                    e.setData({
                        settingInfo: i.data
                    });
                    var s = i.data;
                    if (2 == e.data.member_type) {
                        if (0 == s.debtor_goods_count) return void wx.showModal({
                            title: "请先购买指定商品",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageA/detail_v2/detail_v2?id=" + s.debtor_goods_id
                                }) : t.cancel && wx.redirectTo({
                                    url: "/packageF/debt/debtindex/debtindex"
                                });
                            }
                        });
                        if (s.is_supplier) return void wx.showModal({
                            title: "",
                            content: "您是供应商,暂时无法申请成为债务人",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && wx.redirectTo({
                                    url: "/packageF/debt/debtindex/debtindex"
                                });
                            }
                        });
                        if (s.is_vip) return void wx.showModal({
                            title: "",
                            content: "您是VIP,暂时无法申请成为债务人",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && wx.redirectTo({
                                    url: "/packageF/debt/debtindex/debtindex"
                                });
                            }
                        });
                    }
                    if (1 == e.data.member_type) {
                        if (0 == s.owner_goods_count) return void wx.showModal({
                            title: "请先购买指定商品",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageA/detail_v2/detail_v2?id=" + s.owner_goods_id,
                                    fail: function(t) {
                                        console.log(t), wx.redirectTo({
                                            url: "/packageA/detail_v2/detail_v2?id=" + s.owner_goods_id
                                        });
                                    }
                                }) : t.cancel && wx.redirectTo({
                                    url: "/packageF/debt/debtindex/debtindex"
                                });
                            }
                        });
                        if (s.is_vip) return void wx.showModal({
                            title: "",
                            content: "您是VIP,暂时无法申请成为债权人",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && wx.redirectTo({
                                    url: "/packageF/debt/debtindex/debtindex"
                                });
                            }
                        });
                    }
                    if (3 == e.data.member_type) {
                        if (1 == s.last_apply_is_refund && wx.showModal({
                            title: "",
                            content: "申请被驳回，请重新申请",
                            showCancel: !1,
                            success: function(t) {}
                        }), 0 == s.vip_goods_count) return void wx.showModal({
                            title: "请先购买指定商品",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageA/detail_v2/detail_v2?id=" + s.vip_goods_id
                                }) : t.cancel && wx.redirectTo({
                                    url: "/packageF/debt/debtindex/debtindex"
                                });
                            }
                        });
                        (1 == s.is_owner || s.is_debtor) && wx.showModal({
                            title: "",
                            content: "您无法申请成为vip",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && wx.redirectTo({
                                    url: "/packageF/debt/debtindex/debtindex"
                                });
                            }
                        });
                    }
                } else wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});